package abak.tr.com.boxedverticalseekbar.slice;


import abak.tr.com.boxedverticalseekbar.BoxedVertical;

import abak.tr.com.boxedverticalseekbar.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.Text;
import ohos.agp.window.dialog.ToastDialog;

/**
 * 主要slice
 */
public class MainAbilitySlice extends AbilitySlice implements Component.ClickedListener {
    private Text valueTextView;
    private BoxedVertical bv;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        valueTextView = (Text) findComponentById(ResourceTable.Id_text_value);
        Button bt10 = (Button) findComponentById(ResourceTable.Id_bt_10);
        bt10.setClickedListener(this);
        Button bt20 = (Button) findComponentById(ResourceTable.Id_bt_20);
        bt20.setClickedListener(this);
        Button bt40 = (Button) findComponentById(ResourceTable.Id_bt_40);
        bt40.setClickedListener(this);
        Button bt100 = (Button) findComponentById(ResourceTable.Id_bt_100);
        bt100.setClickedListener(this);
        Button bt500 = (Button) findComponentById(ResourceTable.Id_bt_500);
        bt500.setClickedListener(this);
        Button bt1000 = (Button) findComponentById(ResourceTable.Id_bt_1000);
        bt1000.setClickedListener(this);
        initBoxVer();
    }

    private void initBoxVer() {
        bv = (BoxedVertical) findComponentById(ResourceTable.Id_boxSeekbar);
        bv.setOnBoxedPointsChangeListener(new BoxedVertical.OnValuesChangeListener() {
            @Override
            public void onPointsChanged(BoxedVertical boxedPoints, final int points) {
                valueTextView.setText("Current Value is " + String.valueOf(points));
            }

            @Override
            public void onStartTrackingTouch(BoxedVertical boxedPoints) {
//                new ToastDialog(getContext()).setText("onStartTrackingTouch").setDuration(2000).show();
            }

            @Override
            public void onStopTrackingTouch(BoxedVertical boxedPoints) {
//                new ToastDialog(getContext()).setText("onStopTrackingTouch").setDuration(2000).show();
            }
        });
        valueTextView.setText("Current Valuex is " + bv.getValue());
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()) {
            case ResourceTable.Id_bt_10:
                bv.setCornerRadius(10);
                showDialog("New corner radius is 10");
                break;
            case ResourceTable.Id_bt_20:
                bv.setCornerRadius(20);
                showDialog("New corner radius is 20");
                break;
            case ResourceTable.Id_bt_40:
                bv.setCornerRadius(40);
                showDialog("New corner radius is 40");
                break;
            case ResourceTable.Id_bt_100:
                bv.setMax(100);
                showDialog("New max value is 100");
                break;
            case ResourceTable.Id_bt_500:
                bv.setMax(500);
                showDialog("New max value is 500");
                break;
            case ResourceTable.Id_bt_1000:
                bv.setMax(1000);
                showDialog("New max value is 1000");
                break;
        }
    }

    private void showDialog(String text) {
        new ToastDialog(this).setText(text).show();
    }
}
